import logging
import logging.handlers
import sys
import config


_console_logger = logging.StreamHandler(stream=sys.stdout)
_file_logger = logging.handlers.TimedRotatingFileHandler(f"{config.LOG_PATH}/log_", when="midnight", encoding="utf-8")
_file_logger.suffix = "%Y-%m-%d.log"


def setup():
    if config.DEBUG:
        level = "DEBUG"
    else:
        level = "INFO"
    logging.basicConfig(level=level,
                        format="%(asctime)s %(name)s [%(levelname)s] %(message)s",
                        datefmt="%Y-%m-%d %H:%M:%S",
                        handlers=[_console_logger, _file_logger])
